package com.fbty.mt.dwr;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.fbty.base.domain.Page;
import com.fbty.base.dwr.DwrAuthHelper;
import com.fbty.mt.domain.IpInfo;
import com.fbty.mt.service.IpService;
import com.fbty.mt.utils.BatchSpeed;
import com.fbty.mt.utils.DateTool;

public class InfoDwr {
	private IpService ipInfoService;
	
	private List<IpInfo> ipInfos;
	/**
	 * 分页显示共享类ip
	 * @param pageNo
	 * @param flag
	 * @param parms
	 * @return
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public Page pageIpInsos(Integer pageNo,boolean flag,Map parms) {
		/*Integer num = (Integer) DwrAuthHelper.getSession().getAttribute("num");
		num = num==null?0:num;
		if(num<=0 && !(DwrAuthHelper.getUser().getMember()==1)) {
			return new Page();
		}*/
		Page page = ipInfoService.pageIpInsos(pageNo, Page.PRODUCT_PAGE_SIZE,flag,parms);
		
		ipInfos = page.getResult();
		
		return page;
	}
	
	public List<IpInfo> querySpeed(){
		List<IpInfo> list = BatchSpeed.getSpeed(ipInfos);
		return list;
	}
	/**
	 * 分页显示我的代理
	 * @param pageNo
	 * @param parms
	 * @return
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public Page pageMyIpInfos(Integer pageNo,Map parms) {
		Integer uid = DwrAuthHelper.getUser().getId();
		if("".equals(parms.get("startDate"))){
			parms.put("startDate",0);
		}
		if("".equals(parms.get("endDate"))){
			parms.put("endDate", DateTool.parseDateToString(new Date(218332745325454L)));
		}
		parms.put("uid", uid);
		return ipInfoService.pageMyIpInfos(pageNo, Page.PRODUCT_PAGE_SIZE,parms);
	}
	/**
	 * 批量删除用户已代理的ip
	 * @param params
	 */
	public void deleteForMyIp(int[] cid) {
		ipInfoService.deleteForMyIp(cid);
	}
	/**
	 * 得到包月用户这个在有效时间内还有多少条可以用
	 * @return
	 */
	public String getMsg() {
		return ipInfoService.getMsg(DwrAuthHelper.getUser().getId());
	}
	/**
	 * 批量删除共享类ip
	 * @param ids
	 */
	public void deleteInfo(int[] cid) {
		//Integer roleId = DwrAuthHelper.getUser().getMember();
//		if(roleId==1){
//			ipInfoService.deleteInfo(cid);
//		}
	}
	/**
	 * 批量删除独享类ip
	 * @param ids
	 */
	public void deleteOnlyInfo(int[] cid) {
		/*Integer roleId = DwrAuthHelper.getUser().getMember();
		if(roleId==1){
			ipInfoService.deleteOnlyInfo(cid);
		}*/
	}
	public IpService getIpInfoService() {
		return ipInfoService;
	}

	public void setIpInfoService(IpService ipInfoService) {
		this.ipInfoService = ipInfoService;
	}
	
	
}
